//积分提现post接口，提交参数为 银行卡号id+积分数integration
var integralWDURL = "/addBankCard";
//获取银行卡信息
var getBankCard = "./json/myBankCard.json";
// var getBankCard = "http://localhost:8080/hjcr-wechat/bankcard/getUserBankCrad";
$(document).ready(function(){
  $.get(getBankCard,{params:{userId:sessionStorage.userId}},function(res) {
    if(res.serviceResult){
      var data = res.resultParm.list;
      if(sessionStorage.cardId===undefined){
        var str = data[0].number;
        $(".carInfoName").text(bankName(data[0].bank));
        $(".carInfoNum").text(str.substring(str.length-4,str.length));
        sessionStorage.cardId = data[0].id;
      }
      else {
        var index;
        for (var i = 0; i < data.length; i++) {
          if(data[i].id==sessionStorage.cardId){
            index = i;break;
          }
        }
        $(".carInfoName").text(bankName(data[index].bank));
        var str = data[index].number;
        $(".carInfoNum").text(str.substring(str.length-4,str.length));
      }
    }
  })

  $(".huilv").text(sessionStorage.rate);
  $(".jifen").text(sessionStorage.integral);
  $("#price").on("change",function(){
    $(".number").text($("#price").val()/sessionStorage.rate);
  });

  $("button").click(function(){
		var money = parseInt($("#price").val());

		if(money<=parseInt(sessionStorage.integral) && money!=""){
			$.post(integralWDURL,{
				integration:money,
				id:sessionStorage.cardId
			},function(res){
				alert(res.resultInfo);
				// if(res.serviceResult){history.back();}
			});
		}
		else {
			alert("最多提现"+sessionStorage.integral+"个积分");
		}
	});

});
